package com.gaofei.jpa.dao;

import com.gaofei.jpa.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : gaofee
 * @date : 15:03 2021/5/24
 * @码云地址 : https://gitee.com/itgaofee
 *
 * spring-data-elasticsearch 使用是完全一样的
 *
 * 写一个借口继承JpaRepository ,此时改接口就自动具备了简单的CRUD的功能
 */
public interface UserDao extends JpaRepository<UserEntity,Long> {
    @Query(nativeQuery=true,value = "select u.* ,u.password as ss from tb_user u")
    List<UserEntity> findA();

    List<UserEntity> findUserEntityByUsernameLike(String key);
    List<UserEntity> findUserEntityByUsernameLikeAndPasswordEquals(String key,String password);
    //JPQL语句
//    @Query("from UserEntity where username = ?1 and password = ?2")
//    List<UserEntity> findU(String username,String password);

//    @Query(nativeQuery=true ,value = "select * from 表  where 条件  limit 0,1")
//    @Query("from UserEntity where username = :uname and password = :pwd")
//    List<UserEntity> findU(@Param("uname") String username, @Param("pwd") String password);


    /*@Query("from UserEntity where username = #{#user.username} and password = #{#user.password}")
    List<UserEntity> findU(@Param("user") User user);*/

    //增删改,都可以用这俩注解
//    @Query(nativeQuery=true ,value = "insert into 表  set  ")
//    @Modifying  //对数据有改变的,就加此注解
//    int insert(UserEntity u);
}
